package cn.zn.modules.pz.his.entity.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
public class PzAttachmentVO {
    private String id;
    private String pathRelative;
    private String title;
    private String realName;
    private String suffix;
    private Long size;
    @JsonIgnore
    private String fileDomain;

    public PzAttachmentVO(){}

    public PzAttachmentVO(String fileDomain) {
        this.fileDomain = fileDomain;
    }

    public String getSizeM() {
        return new BigDecimal(Float.valueOf(size) / 1024 / 1024).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue() + " M";
    }

    public String getThumbnailPath() {
        if (pathRelative.lastIndexOf(".") != -1) {
            return this.fileDomain.concat(pathRelative.substring(0, pathRelative.lastIndexOf(".")).concat("_thumbnail").concat(pathRelative.substring(pathRelative.lastIndexOf("."))));
        } else {
            return this.fileDomain.concat(pathRelative.concat("_thumbnail"));
        }
    }

    public String getViewPath() {
        return this.fileDomain.concat(this.pathRelative);
    }
}
